<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="直播间编号">
              <a-input placeholder="请输入直播间编号" v-model="queryParam.roomId"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="直播间名称">
              <a-input placeholder="请输入直播间名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="直播状态">
              <a-select :default-value="null" v-model="queryParam.liveStatus" @change="searchQuery">
                <a-select-option :value="null">
                  全部
                </a-select-option>
                <a-select-option :value="101">
                  直播中
                </a-select-option>
                <a-select-option :value="102">
                  未开始
                </a-select-option>
                <a-select-option :value="103">
                  已结束
                </a-select-option>
                <a-select-option :value="104">
                  禁播
                </a-select-option>
                <a-select-option :value="105">
                  暂停
                </a-select-option>
                <a-select-option :value="106">
                  异常
                </a-select-option>
                <a-select-option :value="107">
                  已过期
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="开始时间">
              <j-date placeholder="请选择开始时间" v-model="queryParam.startTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="结束时间">
              <j-date placeholder="请选择结束时间" v-model="queryParam.endTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"></j-date>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <a-button @click="searchQuery" type="primary" icon="plus">刷新</a-button>

    </div>

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination"
        :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="liveStatus" slot-scope="text">
          <span v-if="text==101">直播中</span>
          <span v-if="text==102">未开始</span>
          <span v-if="text==103">已结束</span>
          <span v-if="text==104">禁播</span>
          <span v-if="text==105">暂停</span>
          <span v-if="text==106">异常</span>
          <span v-if="text==107">已过期</span>
        </template>
        <template slot="goods" slot-scope="text,record">
          {{record.goods.length}}
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="numToFixed2Slot" slot-scope="text">
          {{text|numToFixed2}}
        </template>
        <template slot="startTime" slot-scope="text">
          {{text|timestampToTime1}}
        </template>
        <template slot="endTime" slot-scope="text">
          {{text|timestampToTime1}}
        </template>
        <template slot="sequence" slot-scope="text">
          <div>
            {{text}}
          </div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" @click="openUrlView(text)" height="55px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handlePageDetail(record)">明细</a>
        </span>

      </a-table>
    </div>

    <Gms-mini-live-good-ref ref="gmsMiniLiveGoodRef"></Gms-mini-live-good-ref>

  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/MyJeecgListMixin'
import { getAction, postAction, putAction } from '@/api/manage'
import JDate from '@/components/jeecg/JDate.vue'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import GmsMiniLiveGoodRef from './modules/GmsMiniLiveGoodRef'


export default {
  name: 'LbmsGoodList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
    JDictSelectTag,
    GmsMiniLiveGoodRef
  },
  data () {
    return {
      select_id: null,
      description: '商品管理页面',
      // 表头
      columns: [
        {
          title: '直播间编号',
          align: "center",
          dataIndex: 'roomId'
        },
        {
          title: '直播名称',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '直播状态',
          align: "left",
          dataIndex: 'liveStatus',
          scopedSlots: { customRender: "liveStatus" }
        },
        {
          title: '主播名称',
          align: "center",
          dataIndex: 'anchorName'
        },
        {
          title: '计划开播时间',
          align: "center",
          dataIndex: 'startTime',
          scopedSlots: { customRender: "startTime" }
        },
        {
          title: '计划结束时间',
          align: "center",
          dataIndex: 'endTime',
          scopedSlots: { customRender: "endTime" }
        },
        {
          title: '直播商品数量',
          align: "right",
          dataIndex: 'goods',
          scopedSlots: { customRender: "goods" }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/mallPlus/miniLive/list"
      },
      dictOptions: {},
    }
  },
  created () {
    this.isorter = {
      column: 'sequence',
      order: 'asc',
    }
    this.loadData()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    loadData (arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams()//查询条件

      this.loading = true
      postAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
          this.onClearSelected()
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },

    handlePageDetail (record) {
      let self = this
      self.$refs.gmsMiniLiveGoodRef.open(record)
      self.$refs.gmsMiniLiveGoodRef.visible = true
    },
    initDictConfig () {
    },

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>